package com.chenliang.dao;

import com.chenliang.domain.Permission;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ProjectName: mavenSSM
 * @Package: com.chenliang.dao
 * 作用：
 */
public interface IPermission {
    @Select("select * from permission where id in(select permissionId from ROLE_PERMISSION  where roleId=#{id}) ")
    List<Permission> findById();

    @Select("select * from permission")
    List<Permission> findAll();

@Insert("insert into permission values(SYS_GUID(),#{permissionName},#{url})")
    void permissionAdd(Permission permission);



    //通过权限查找角色再找用户
@Select("select * from permission where id=#{id} ")
@Results(value = {
        @Result(id = true,property = "id",column = "id"),
        @Result(property = "roles" ,column = "id",javaType = java.util.List.class,many = @Many(select = "com.chenliang.dao.IRoledao.findByPermissionId",fetchType = FetchType.EAGER))
})
Permission findByIdPermission(String Id);
}
